<div data-ng-controller="contractIncomeCtrl">
    <style type="text/css">
        tr.selected {
            background-color: #f2f2f2;
        }
    </style>
    <div class="table-header clearfix ng-scope">
        <span class="fl lh30 f14">{{contractBaseInfo.contract_code}}</span>
    </div>
    <form class="form-horizontal">
        <div class="form-group mt10">
            <span class="col-sm-2 control-label ml15">账套公司</span>

            <div class="col-sm-5">
                <input select2 ng-model="contractBaseInfo.account_company_id" select2-model="ddl2Customer"
                       config="ddlConfigCompany" class="form-control" type="text"/>
            </div>
        </div>
    </form>

    <h3>收入信息</h3>
    <div class="mt20 clearfix ng-scope ml25"
         ng-if="contractBaseInfo.is_cancelled == 0">
        <button class="btn permission p-1602-tablecell"
                ng-show="userAuthList.indexOf('0001') !== -1"
                ng-click="addIncome()">
            新增收入
        </button>
    </div>
    <form name="contractIncomeEdit" id="grid" class="table-wrap mt10 ml25" style="min-height: 200px;">
        <table width="100%">
            <thead>
            <tr>
                <th width="40">序号</th>
                <th width="130">财务收入项</th>
                <th width="90">确认方式</th>
                <th width="80">收入项编码</th>
                <th width="200">收入开始日期</th>
                <th width="245" class="align-m">权益日期</th>
                <th width="120">收入金额</th>
                <th width="120">累计已确认金额</th>

                <th width="120">已确认收入发生坏账</th>
                <th width="120">未确认收入发生坏账</th>
                <th width="120">金蝶核销坏账</th>

                <th width="120">未确认金额</th>
                <th width="108">状态</th>
                <th width="108" class="permission p-1602-tablecell">操作</th>
            </tr>
            </thead>
            <tbody
                ng-repeat="record in incomes"
                ng-if="record.__type != 'delete'"
            >
            <tr
                class="{{selectedRevenueId === record.revenue_id ? 'selected' : ''}}"
                data-ng-click="onSelectRevenue(record)"
            >
                <td height="40"><p ng-bind="$index + 1"></p></td>
                <td class="lh14">
                    <p ng-if="record.is_carry_over == true || (record.editMode || 0)  == 0" ng-bind="record.finance_type_name"></p>
                    <p ng-if="((record.editMode || 0) != 0 && record.is_carry_over == false)">
                        <input
                            select2
                            ng-model="record.revenue_type"
                            select2-model="record.ddl2Category"
                            data="record"
                            config="ddlConfigFinance"
                            class="form-control"
                            type="text"
                        />
                    </p>
                </td>
                <td>
                    {{record.revenue_type | f_revenue_type}}
                </td>
                <td>
                    <p ng-bind="record.income_code"></p>
                </td>
                <td>
                    <p ng-if="record.is_carry_over == true || record.editMode != 1" ng-bind="record.establish_time | strdate:'yyyy-MM-dd'"></p>
                    <p ng-if="(record.editMode == 1 && record.is_carry_over == false) ">
                        <input
                                ui-date format="yyyy-MM-dd"
                                required
                                ng-model="record.establish_time"
                                class="form-control align-r"
                                type="text"
                        />
                    </p>
                </td>
                <td>
                    <p ng-if="record.revenue_type == '7f94a5d3-fcf6-11e4-bed8-00155d02c832' && record.editMode != 1" class="align-m">
                        -
                    </p>
                    <p ng-if="record.revenue_type != '7f94a5d3-fcf6-11e4-bed8-00155d02c832' && record.editMode != 1" class="align-m">
                        {{record.begin_on|strdate:'yyyy-MM-dd'}}至{{record.end_on|strdate:'yyyy-MM-dd'}}
                    </p>
                    <p ng-if="(record.editMode == 1 && record.is_carry_over == false) ">
                        <input
                                ui-date format="yyyy-MM-dd"
                                required
                                ng-model="record.begin_on"
                                class="form-control align-r"
                                type="text"
                        />
                        至
                        <input
                            ui-date format="yyyy-MM-dd"
                            required
                            ng-model="record.end_on"
                            class="form-control align-r"
                            type="text"
                        />
                    </p>
                </td>
                <td>
                    <p ng-if="record.is_carry_over == true || record.editMode != 1" ng-bind="record.amount|number:2"></p>

                    <p ng-if="(record.editMode == 1 && record.is_carry_over == false)">
                        <input
                            income
                            ng-model="record.amount"
                            class="form-control align-r"
                            type="text"
                            data-ng-click="stopPropagation($event)"
                        />
                    </p>
                </td>

                <td>
                    <p ng-bind="record.total_recognition_amount|number:2"></p>
                </td>


                <td>
                    <p ng-if="(record.editMode || 0)  == 0" ng-bind="record.recognized_bad_debt_amount|number:2"></p>

                    <p ng-if="((record.editMode || 0)  != 0)">
                        <input
                            number
                            ng-model="record.recognized_bad_debt_amount"
                            class="form-control align-r"
                            type="text"
                            data-ng-click="stopPropagation($event)"
                        />
                    </p>
                </td>
                <td>
                    <p ng-if="(record.editMode || 0)  == 0" ng-bind="record.unrecognized_bad_debt_amount|number:2"></p>

                    <p ng-if="((record.editMode || 0)  != 0)">
                        <input
                            number
                            ng-model="record.unrecognized_bad_debt_amount"
                            class="form-control align-r"
                            type="text"
                            data-ng-click="stopPropagation($event)"
                        />
                    </p>
                </td>
                <td>
                    <p ng-if="(record.editMode || 0)  == 0" ng-bind="record.kingdee_bad_debt_amount|number:2"></p>

                    <p ng-if="((record.editMode || 0)  != 0)">
                        <input
                            number
                            ng-model="record.kingdee_bad_debt_amount"
                            class="form-control align-r"
                            type="text"
                            data-ng-click="stopPropagation($event)"
                        />
                    </p>
                </td>


                <td>
                    <p ng-bind="record.unrecognized_amount|number:2"></p>
                </td>

                <td>
                    {{record.close_status | state}}
                </td>
                <td data-ng-click="stopPropagation($event)" class="permission p-1602-tablecell">
                    <div
                        ng-if="contractBaseInfo.contract_status == 0 || contractBaseInfo.contract_status == 2"
                        ng-show="userAuthList.indexOf('0001') !== -1"
                    >
                        <a ng-if="allowEdit(record, contractBaseInfo)" href="javascript:void(0)" title="修改收入信息" ng-click="edit(record, contractBaseInfo)">修改</a>
                        <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)" title="保存收入信息" ng-click="contractIncomeEdit.$valid && saveRevenue(record)">确定</a>
                        <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)" title="取消修改收入信息" ng-click="editIncomeCancel(record, $index)">取消</a>
                        <br/>
                        <a ng-if="record.parent_id == '' && record.revenue_id" href="javascript:void(0)" ui-dialog="红冲" ui-dialog-data="{isEdit: false}" ui-dialog-show="onIncomeRedFlushAddShow($dialog, $dialogScope, record)" ui-dialog-ok="saveIncomeRedFlush($dialog, $dialogScope)" ui-dialog-cache="false" ui-dialog-url="/contract/pages/income/incomeRedFlush.html">红冲</a>


                        <!--<div ng-if="record.close_status == 1" >-->
                            <!--<a href="javascript:void(0)" title="关闭收入信息" ng-click="contractIncomeEdit.$valid && saveRevenue(record,{closeStatus:2})" >关闭</a>-->
                        <!--</div>-->

                        <!--<div>-->
                            <!--<a ng-click="delIncome(record)" href="javascript:void(0)" title="删除收入信息" >删除</a>-->
                        <!--</div>-->
                    </div>
                </td>
            </tr>
            <tr ng-if="selectedRevenue === record">
                <td colspan="15">
                    <h4>结转信息</h4>
                    <div class="table-wrap mt10 ml10 mr10" style="margin-bottom: 10px">
                        <table ng-if="!record.__loadingRecognition" width="100%">
                            <thead>
                            <tr>
                                <th width="40">序号</th>
                                <th width="130">结转期间</th>
                                <th width="130">上期累计确认收入</th>
                                <th width="130">当期累计确认收入</th>
                                <th width="130">当期确认收入</th>
                                <th width="130">结转人</th>
                                <th width="130">结转时间</th>
                                <th width="108">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr
                                ng-repeat="recognitionItem in revenueRecognitionList"
                            >
                                <td height="40"><p ng-bind="$index + 1"></p></td>
                                <td>
                                    <p ng-if="recognitionItem.recognition_begin" class="align-m">
                                        {{recognitionItem.recognition_begin|strdate:'yyyy-MM-dd'}}至{{recognitionItem.recognition_end|strdate:'yyyy-MM-dd'}}
                                    </p>
                                </td>
                                <td>
                                    <p ng-bind="recognitionItem.last_issue_total_recognition_amount|number:2"></p>
                                </td>
                                <td>
                                    <p ng-bind="recognitionItem.this_issue_total_recognition_amount|number:2"></p>
                                </td>
                                <td>
                                    <p
                                        ng-if="(recognitionItem.editMode || 0)  == 0"
                                        ng-bind="recognitionItem.recognition_amount|number:2"
                                    ></p>

                                    <p ng-if="((recognitionItem.editMode || 0)  != 0)">
                                        <input
                                            number
                                            ng-model="recognitionItem.recognition_amount"
                                            class="form-control align-r"
                                            type="text"
                                        />
                                    </p>
                                </td>

                                <td>
                                    <p ng-bind="recognitionItem.recognition_by"></p>
                                </td>

                                <td>
                                    <p>{{recognitionItem.recognition_date|strdate:'yyyy-MM-dd'}}</p>
                                </td>

                                <td>
                                    <div
                                        ng-if="contractBaseInfo.contract_status == 0 || contractBaseInfo.contract_status == 2"
                                        ng-show="userAuthList.indexOf('0001') !== -1">
                                        <a ng-if="allowEdit(recognitionItem, contractBaseInfo)"
                                           href="javascript:void(0)"
                                           title="修改收入信息"
                                           ng-click="edit(recognitionItem, contractBaseInfo)"
                                        >
                                            修改
                                        </a>

                                        <a
                                            ng-if="(recognitionItem.editMode || 0)  != 0"
                                            href="javascript:void(0)"
                                            title="保存结转收入信息"
                                            ng-click="updateRecognition(recognitionItem)"
                                        >确定</a>
                                        <a ng-if="(recognitionItem.editMode || 0)  != 0" href="javascript:void(0)"
                                           title="取消修改结转收入信息"
                                           ng-click="editIncomeCancel(recognitionItem, $index)">取消</a>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <div class="align-m" ng-if="record.__loadingRecognition">加载中...</div>
                        <div class="no-data" ng-if="!record.__loadingRecognition && revenueRecognitionList.length===0"><span>暂无数据</span></div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="no-data" ng-if="!incomes || incomes.length==0"><span>暂无数据</span></div>
    </form>
    <div class="ml25 mt10 c-red">
        <span class="pl10">收入项总金额：{{sum_all}}元</span>
        <span class="pl10">云客租用金额：{{sum_rent_time}}元</span>
        <span class="pl10">云客增值金额：{{sum_one_time}}元</span>
        <span class="pl10">广告金额：{{sum_ad}}元</span>
        <span class="pl10">销售金额：{{sum_sale}}元</span>
    </div>
    <div class="ml35 mt10 c-red"
         ng-show="!isSpecial(contractBaseInfo.contract_property_id) && (contractBaseInfo.sign_amount | noEqual: productTotalAmount)">
        提示：合同签约金额不等于产品标准总额之和，请手工调整收入金额。
    </div>
</div>
